\documentclass[a4paper]{article}
\usepackage[affil-it]{authblk}
\usepackage{geometry}
\geometry{margin=1.5cm}
\usepackage{amsmath}


\begin{document}
	% =========================================================
	\title{Numerical Analysis Homework}
	
	\author{YueLiang 3220100159}
	\affil{Electronic address: \texttt{3220100159@zju.edu.cn}}
	\affil{Information and Computing Science 2201, Zhejiang University}
	
	\date{Due time: \today}
	
	\maketitle

	
	% ============================================
	\section*{A.Implementation of Numerical Methods in C++}
	\subsection*{Objective}
	Implement the bisection method, Newton's method, and the secant method in a C++ package.
	\begin{itemize}
		\item (a) Design an abstract base class \texttt{EquationSolver} with a pure virtual method \texttt{solve}.
		\item (b) Write a derived class of \texttt{EquationSolver} for each method to accommodate its particularities in solving nonlinear equations.
	\end{itemize}
	
	\subsection*{Function.hpp}
	Design a function class with a pure virtual function \texttt{operator()(double x) const} that evaluates the function at a given point \( x \). Include another virtual function to calculate the derivative using differential calculus.
	
	\subsection*{EquationSolver.hpp}
	Design an abstract base class \texttt{EquationSolver} that declares a pure virtual function \texttt{solve}. This function is overridden in each derived class to provide the specific implementation of the method.
	\begin{itemize}
		\item Bisection Method: The \texttt{Bisection\_Method} class takes an interval \([a, b]\) and iteratively narrows it down to find a root of the function.
		\item Newton's Method: The \texttt{Newton\_Method} class uses an initial guess \( x_0 \) and refines it using the derivative of the function.
		\item Secant Method: The \texttt{Secant\_Method} class uses two initial guesses \( x_0 \) and \( x_1 \) to approximate the derivative needed for Newton's method.
	\end{itemize}
	
	\section*{B.Testing Implementation by Bisection method}
	Test your implementation of the bisection method on the following functions and intervals:
	\begin{itemize}
		\item \( x^{-1} - \tan(x) \) on \([0, \frac{\pi}{2}]\)
		\item \( x^{-1} - 2^x \) on \([0, 1]\)
		\item \( 2^{-x} + e^x + 2\cos(x) - 6 \) on \([1, 3]\)
		\item \( \frac{x^3 + 4 \cdot x^2 + 3x + 5}{2x^3 - 9x^2 + 18x - 2} \) on \([0, 4]\)
	\end{itemize}
	Each derived class (\texttt{F1}, \texttt{F2}, \texttt{F3}, \texttt{F4}) imports the functions needed. Each function sets up a \texttt{Bisection\_Method} solver with a specific function object and interval, then invokes the \texttt{solve} method to find a root and prints the result.
	\begin{enumerate}
		\item 0.860334
		\item 0.641186
		\item 1.82938
		\item 0.117877
	\end{enumerate}
	\section*{C.Test Implementation by Newton's method}
	Testing your implementation of Newton's method by solving \(x=tanx\),.Find the roots near and 7.7.
		The derived class (\texttt{F}) imports the functions needed.Run and print the result.
	\begin{enumerate}
		\item 4.71239
	\end{enumerate}
	\section*{D.Testing Implementation by Secant method}
	Test your implementation of the secant method on the following functions and intervals:\\
		1\\
		\( sin(\frac{x}{2})-1 with x_0=0,x_1=\frac{\Pi}{2},\)\\
		\( e^{x}-tan(x) with x_0=1,x_1=1.4,\)\\
		\( x^{3}-12*x^{2}+3*x+1 with x_0=0,x_1=-0.5\)\\
		2.\\
		\(\sin\left(\frac{x}{2}\right) - 1\) with \(x_0 = 0\), \(x_1 = \frac{\pi}{2}\)\\
		\( e^{x}-tan(x) with x_0=1.4,x_1=1.8,\)\\
		\( x^{3}-12*x^{2}+3*x+1 with x_0=0,x_1=0.5\)\\
	Run and print the result.\\
		1.\\
		3.14093\\
		1.30633\\
		-0.188685\\
		2.\\
		3.14159\\
		1.30633\\
		0.451543\\
	\section*{E.Application of those numerical methods}
	The problem involves calculating the depth of water (\(h\)) in a trough with a semi-circular cross-section, provided the trough's length (\(L\)), radius (\(r\)), and water volume (\(V\)). The formula for the volume of water in the trough is given by:
	\[ V = L\left[0.5\pi r^{2} - r^{2}\arcsin\frac{h}{r} - h\left(r^{2} - h^{2}\right)^{\frac{1}{2}}\right] \]
	\subsection*{Objective}
	To find the depth of water (\(h\)) with a precision of 0.01 ft using the bisection method.
	\subsection{Bisection Method}
	The bisection method is a root-finding method that repeatedly bisects an interval and selects a subinterval in which a root must lie. This method was implemented in the C++ class `Bisection\_Method`, which takes an interval \([a, b]\) and iteratively narrows it down to find a root.
	\subsection{Newton's Method}
	Newton's method uses the derivative of the function to approximate the root, converging quickly if the initial guess is close to the actual root. It is more efficient than the bisection method near the root.
	\subsection{Secant Method}
	The secant method is an alternative to Newton's method that does not require the calculation of the derivative. It uses two initial guesses to approximate the derivative and can be effective if the initial guesses are reasonably close to the root.
	\subsection*{Implementation}
	The C++ code defines a class F that implements the Function interface. The operator() calculates the difference between the given formula and the known volume \(V\). The solve\_f() function initializes the bisection solver with the interval [0, 0.01] and invokes the solve method to find the root.
	
	\subsection*{Results}
	The bisection method was used to find the depth of water with the given parameters ( \(L = 10\) ft, \(r = 1\) ft, \(V = 12.4\) ft\(^3\)). The result was printed to the console:\\
	Solving with Bisection Method:\\
	Root found: 0.0798688\\
	Solving with Newton's Method:\\
	Root found: 0.0798688\\
	Solving with Secant Method:\\
	Root found: 0.0798688\\
	\section{F.Application of Newton's and Secant method}
	\subsection*{Introduction}
	In the design of all-terrain vehicles, it is crucial to consider the vehicle's ability to cross obstacles without experiencing hang-up or nose-in failures. This report focuses on the nose-in failure, where the vehicle's nose touches the ground when descending into a ditch. We determine the maximum angle $\alpha$ that the vehicle can approach an obstacle at, given the maximum angle $\beta_1$ at which a hang-up failure does not occur.
	
	\subsection*{a.Use Newton's method to verify \(\alpha \approx 33^\circ,l=89in, h = 49in,D=55in,\beta1=11.5^\circ\).}
	
	We need to find the angle $\alpha$ that satisfies the equation:
	\[ A\sin\alpha\cos\alpha + B\sin^2\alpha - C\cos\alpha - E\sin\alpha = 0 \]
	By Newton's method,we can find the root by iteration.
	\subsection*{b.Use Newton's method to verify \(\alpha \approx 33^\circ,l=89in, h = 49in,D=33in,\beta1=11.5^\circ\).}
	For b,it is almost the same with a(Only the value of D changed.)
	\subsection*{c.Use the secant method with another initial value as far away as possible from $33^\circ$.Show the result and discuss.}
	\subsection{Result}
	Solving (a)\\
	A root is: 9.57503 degrees\\
	Solving (b)\\
	A root is: 9.66708 degrees\\
	Solving (c)
	Initial value:$5^\circ$,$29^\circ$\\
	A root is: 9.66708 degrees\\
	Initial value:$60^\circ$,$79^\circ$\\
	A root is: -157.238 degrees\\
	Initial value:$78^\circ$,$90^\circ$\\
	A root is: 922.762 degrees
	\subsection{Discussion}
	For (c),we see when the initial value changed a lot,the result changed also heavily.For the first group,the result is the same as $33^\circ$.For the last two groups , the result changed a lot.So we can guess maybe the initial value given is too far from the true root will cause the secant method no longer converge to a certain value.
	
	\section*{Acknowledgement}
	Give your acknowledgements here (if any).
	
	
\end{document}
